<<<<<<< HEAD
package com.shop.controller.admin;

import com.shop.dto.ProductDTO;
import com.shop.dto.ProductPageQueryDTO;
import com.shop.entity.Product;
import com.shop.result.PageResult;
import com.shop.result.Result;
import com.shop.service.ProductService; // 修正导入路径
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
@Api(tags = "商品相关接口")
@Slf4j
public class ProductController {

    @Autowired
    private ProductService productService;

    @PostMapping
    @ApiOperation("新增商品")
    public Result save(@RequestBody ProductDTO productDTO) {
        log.info("新增商品：{}", productDTO);
        productService.save(productDTO);
        return Result.success();
    }

    @GetMapping("/page")
    @ApiOperation("商品分页查询")
    public Result<PageResult> page(ProductPageQueryDTO productPageQueryDTO) {
        log.info("商品分页查询:{}", productPageQueryDTO);
        PageResult pageResult = productService.pageQuery(productPageQueryDTO);
        return Result.success(pageResult);
    }

    @DeleteMapping
    @ApiOperation("商品批量删除")
    public Result delete(@RequestParam List<Long> ids) {
        log.info("商品批量删除：{}", ids);
        productService.deleteBatch(ids);
        return Result.success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询商品")
    public Result<Product> getById(@PathVariable Long id) {
        log.info("根据id查询商品：{}", id);
        Product product = productService.getById(id);
        return Result.success(product);
    }

    @PutMapping
    @ApiOperation("修改商品")
    public Result update(@RequestBody ProductDTO productDTO) { // 修正参数名
        log.info("修改商品：{}", productDTO);
        productService.update(productDTO); // 修正参数类型
        return Result.success();
    }

    @PostMapping("/status/{status}")
    @ApiOperation("商品起售停售")
    public Result<String> startOrStop(@PathVariable Integer status, @RequestParam Long id) {
        productService.startOrStop(status, id);
        return Result.success();
    }

    @GetMapping("/list")
    @ApiOperation("根据分类id查询商品")
    public Result<List<Product>> list(@RequestParam Long categoryId) { // 修正参数名
        List<Product> list = productService.list(categoryId);
        return Result.success(list);
=======
import java.util.ArrayList;
import java.util.List;

// 商品类
class Product {
    private int id;
    private String name;
    private double price;
    private String imageUrl;

    public Product(int id, String name, double price, String imageUrl) {
        this.id = id;
        this.name = name;
        this.price = price;
        this.imageUrl = imageUrl;
    }

    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public double getPrice() {
        return price;
    }

    public String getImageUrl() {
        return imageUrl;
    }

    @Override
    public String toString() {
        return "商品 ID: " + id +
                ", 商品名称: " + name +
                ", 商品价格: " + price +
                ", 图片链接: " + imageUrl;
    }
}

 class ProductListApp {
    public static void main(String[] args) {
        // 创建商品列表
        List<Product> products = new ArrayList<>();
        products.add(new Product(1, "苹果手机", 5999.0, "https://example.com/apple_phone.jpg"));
        products.add(new Product(2, "华为电脑", 8999.0, "https://example.com/huawei_pc.jpg"));
        products.add(new Product(3, "小米平板", 2999.0, "https://example.com/xiaomi_tablet.jpg"));

        // 打印商品列表标题
        System.out.println("商品列表：");
        System.out.println("------------------------------");

        // 遍历并打印每个商品信息
        for (Product product : products) {
            System.out.println(product);
        }
>>>>>>> origin/master
    }
}